//
//  BasNavViewController.swift
//  weibo
//
//  Created by mac on 15/12/23.
//  Copyright (c) 2015年 LYR. All rights reserved.
//

import UIKit

class BasNavViewController: UINavigationController, UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

       //  设置返回手势的代理
        self.interactivePopGestureRecognizer?.delegate = self
    
    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        // 自定义返回的按钮
        // 一旦自定义返回按钮 导航视图控制器的 返回手势的协议对象 会被重置
        if childViewControllers.count != 0 {
           let btn = UIButton(title: "返回", imageName: "navigationbar_back_withtext", backImageName: nil, fontSize: 14, color: UIColor.lightGrayColor())
            
            btn.addTarget(self, action: "back", forControlEvents: .TouchUpInside)
        
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btn)
            
            viewController.hidesBottomBarWhenPushed = true
        
        }
        
        //  调用父类的跳转函数  这句话执行后才会真正跳转页面
        super.pushViewController(viewController, animated: true)

    }

    
    @objc private func back() {
    
      popViewControllerAnimated(true)
    }
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        
//        if childViewControllers.count == 1 {
//            return false
//        }
//        return true
        
        return childViewControllers.count != 1
    }
    
    
   
}



























